﻿@using OBUCare.Web.Infrastructure;
@using OBUCare.Core.Models;
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess;
@using OBUCare.Core.Common;
@{
}
<div style="height: 60px;">
    <h2 style="text-align: center;">
        元器件入库冲正管理</h2>
</div>
<div>
    @Html.Partial("../PartsReport/_StockInSearch")
</div>
<div>
    @(Html.Telerik().Grid<View_PartsStockDetails>()
            .Name("Grid")
            .DataKeys(keys => keys.Add(c => c.ID))
             .Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn))
            .Resizable(resizing => resizing.Columns(true))
            .DataBinding(dataBinding => dataBinding
                        .Ajax().Select("ListPartsStockIn", "Parts", new { sql = "" })
                )
            .Columns(columns =>
            {
                columns.Bound(o => o.AGENT_NAME).Width(150);
                columns.Bound(o => o.PARTS_NAME).Width(120);
                columns.Bound(o => o.SUPPLIER_NAME).Width(100);
                columns.Bound(o => o.SPEC_NAME).Width(120);
                columns.Bound(o => o.RECORD_DATE).Format("{0:yyyy-MM-dd}").Width(150);
                columns.Bound(o => o.OPERATOR_NAME).Width(150);
                columns.Bound(o => o.PARTS_COUNT).Width(150);
                columns.Bound(o => o.ID)
                 .ClientTemplate("<input type='button' value='冲正' name='callBack' id='<#= ID #>' onclick='deleteData(id)' />").Title("冲正").Width(100);  
            }).TableHtmlAttributes(new { style = "width:900px" })
            .Editable(editing => editing.Mode(GridEditMode.PopUp)) 
            .ClientEvents(events =>
                {
                    events.OnError("onError");
                    events.OnDataBinding("onDataBinding");
                })

            .Scrollable(scroll => scroll.Height(CommonStyleForUI.Grid_Height))
            .Pageable(paging =>
            {
            paging.Style(CommonStyleForUI.Grid_PageStyle)
            .Position(CommonStyleForUI.Grid_PagePosition)
            .PageTo(CommonStyleForUI.Grid_CurrentPage)
            .PageSize(CommonStyleForUI.Grid_PageSize, new int[] { 10, 20, 50, 100, 200 });
            })
    )
</div>
<script language="javascript" type="text/javascript">

    function onError(e) {
        //debugger;
        e.preventDefault();
        /*if (e.XMLHttpRequest.status == "505")
        alert("系统字段不允许删除");
        else if (e.XMLHttpRequest.status == "506")
        alert("系统表不允许删除");
        else*/
        alert(e.XMLHttpRequest.getResponseHeader("message"));
    }


    function onDataBinding(e) {
        var grid = $('#Grid').data('tGrid')
        index = (grid.currentPage - 1) * grid.pageSize;
        e.data = {
            // the key ("category") specifies the variable name of the action method which will contain the specified value
            searchSql: $('#searchSql').val(),
            agentNO: $('#agentNO').val()
            //,menuNames: $('#menuNames').val()
        };
    }

    function deleteData(value) {
        if (confirm("确定冲正？")) {
            //debugger;
            var ID = value;
            var jdata = { ID: ID};
            $.post("/Parts/ConfirmCallBack", jdata,
                        function (data) {
                            if (data.success == true) {
                                var grid = $('#Grid').data('tGrid');
                                //                                alert(grid);
                                grid.rebind();
                                alert(data.message);

                            }
                            else {
                                alert(data.message);
                            }
                        });
        }
    }   
</script>
